﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ReplaceFileVersion
{
    public partial class ReplaceJsCommaForm : Form
    {
        public ReplaceJsCommaForm()
        {
            InitializeComponent();
            folderBrowserDialog1.SelectedPath = txtDir.Text = SelectedPath;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var fileV = new ReplaceJsComma(txtDir.Text, txtSearchExt.Text)
            {
            };
            var list = fileV.Replace();
            var path = fileV.WriteLog(list);
            MessageBox.Show("执行完成！","提示");
            if (ckbOpenLog.Checked)
            {
                Process.Start(path);
            }
        }

        private void btnSelectDir_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                SelectedPath = txtDir.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        const string ConfigName = "ReplaceJsCommaFormSelectedPath.data";
        public string SelectedPath
        {
            get
            {
                var conf = Path.GetTempPath() + ConfigName;
                try
                {
                    return File.ReadAllText(conf);
                }
                catch
                {
                }
                return null;
            }
            set
            {
                var conf = Path.GetTempPath() + ConfigName;
                try
                {
                    File.WriteAllText(conf, value);
                }
                catch
                {
                }
            }
        }

    }
}
